<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<input type="text" class="a" /> + <input type="text" class="b"/> = <input type="button" class="sum" value="求和" />
		<script type="text/javascript">
			$(function(){
				$(".sum").click(function(){
					var a = $(".a").val();
					var b = $(".b").val();
					var a1 = a.match(/\d+/ig);
					var b1 = b.match(/\d+/ig);
					var sum_a = 0;
					var sum_b = 0;
					var sum = 0;
					for(var i = 0;i < a1.length;i++){
						a1[i] = parseInt(a1[i],10);
						sum_a += a1[i];
					}
					for(var i = 0;i < b1.length;i++){
						b1[i] = parseInt(b1[i],10);
						sum_b += b1[i];
					}				
					sum = sum_a + sum_b;
					
					alert(sum);
				})
			})
		</script>
	</body>
</html>
